﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Runtime.Serialization;
using System.Web.Script.Serialization;
using System.Collections.ObjectModel;


namespace Facebook.Channels
{
     /// <summary>
     /// Helper type to deserialize the json to a especific type 
     /// </summary>
    public class FBJsonConverter : JavaScriptConverter
    {
        /// <summary>
        /// Creates an FaceBookEntity 
        /// </summary>
        /// <param name="dictionary">properties name/value mapping</param>
        /// <param name="type">the target type to witch the deserialization will execute</param>
        /// <param name="serializer">serializer being used on the deserialization</param>
        /// <see cref="System.Web.Serialization.JavaScriptConverter"/>
        /// <returns>type instance</returns>
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            if (type == typeof(object))
            {
                return new FacebookEntity(dictionary);
            }

            return null;
        }
        /// <summary>
        /// Not Implemented
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Type Supported on deserialization
        /// </summary>
        public override IEnumerable<Type> SupportedTypes
        {
            get { return new ReadOnlyCollection<Type>(new List<Type>(new Type[] { typeof(object) })); }
        }
    }
     

}